from flask import Flask, session, redirect, url_for, escape, request
import os
from flask.ext.script import Manager, Server

app = Flask(__name__)
manager = Manager(app)

# This is a test comment.
# And this is a new test comment.

@app.route('/')
def index():
    if 'username' in session:
        return 'Logged in as %s' % escape(session['username'])

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        session['username'] = request.form['username']
        return redirect(url_for('index'))
    return  '''
    <form action="" method="post">
        <p><input type=text name=username>
        <p><input type=submit value=Login>
    </form>
    '''

@app.route('/about')
def about():
    return "The about page"

@app.route('/logout')
def logout():
    session.pop('username', None)
    return redirect(url_for('index'))

secret = os.urandom(24)
app.secret_key = secret 

manager.add_command('runserver', Server(
    use_debugger = True,
    use_reloader = True,
    host = '0.0.0.0')
    )

if __name__ == '__main__':
    manager.run()
